#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>

int main()
{
    umask(0);
    struct stat st;
    const char* filename = "log.txt";
    int n =stat(filename,&st);
    if(n<0)return -1;
    int fd = open(filename,O_RDONLY);
    if(fd < 0)
    {
        perror("open");
        return -1;
    }
    char* buf = (char*)malloc(st.st_size+1);
    n = read(fd,buf,st.st_size);
    if(n > 0)
    {
        buf[n] = '\0';
        printf("file message = %s",buf);
    }
    //const char* message = "i am file\n";
    //write(fd,message,strlen(message));
    close(fd);
    return 0;
}
